package com.emser.unc.client.view;

import com.emser.unc.client.CloudMobile;
import com.emser.unc.client.presenter.CustomerPopupPresenter;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;

public class CustomerPopupView extends DialogBox implements CustomerPopupPresenter.Display {
	private	TextBox firstName, lastName, address, telephone;
	private Button btnSave, btnCancelar;
	private Label id, lblWFirstName, lblWLastName, lblWAddress, lblWTelephone,lblWCity, lblWZP;
	private TextBox city, zp;
	
	public CustomerPopupView(){
		FlexTable flexTable = new FlexTable();
		flexTable.setStyleName("gwt-FlexTable");
	    flexTable.setSize("397px", "228px");
	    setWidget(flexTable);
	    
	    Label lblId = new Label(CloudMobile.constants.number()+":");
	    flexTable.setWidget(0, 0, lblId);	    
	    flexTable.getCellFormatter().setHeight(0, 0, "20px");
	    flexTable.getCellFormatter().setWidth(0, 0, "150px");
	    lblId.setHeight("100%");
	    
	    id = new Label("");
	    flexTable.setWidget(0, 1, id);
	    flexTable.getCellFormatter().setHeight(0, 1, "20px");
	    flexTable.getCellFormatter().setWidth(0, 1, "200px");
	    id.setSize("200px", "100%");
	    
	    Label lblFirstName = new Label(CloudMobile.constants.name()+":");
	    flexTable.setWidget(1, 0, lblFirstName);	    
	    flexTable.getCellFormatter().setHeight(1, 0, "20px");
	    flexTable.getCellFormatter().setWidth(1, 0, "150px");
	    lblFirstName.setWidth("130px");
	    
	    firstName = new TextBox();
	    flexTable.setWidget(1, 1, firstName);
	    flexTable.getCellFormatter().setHeight(1, 1, "20px");
	    flexTable.getCellFormatter().setWidth(1, 1, "200px");
	    firstName.setSize("200px", "100%");
	    
	    lblWFirstName= new Label(CloudMobile.constants.wInvalidate());
	    lblWFirstName.setStyleName("gwt-LblWarning");
	    flexTable.setWidget(1, 2, lblWFirstName);
	    lblWFirstName.setWidth("100%");
	    flexTable.getCellFormatter().setHeight(1, 2, "20px");
	    flexTable.getCellFormatter().setWidth(1, 2, "130px");
	    lblWFirstName.setVisible(false);
	    
	    
	    Label lbLastName= new Label(CloudMobile.constants.lastName()+":");
	    flexTable.setWidget(2, 0, lbLastName);
	    flexTable.getCellFormatter().setHeight(2, 0, "20px");
	    flexTable.getCellFormatter().setWidth(2, 0, "150px");
	    
	    
	    lastName = new TextBox();
	    flexTable.setWidget(2, 1, lastName);
	    flexTable.getCellFormatter().setHeight(2, 1, "20px");
	    flexTable.getCellFormatter().setWidth(2, 1, "200px");
	    lastName.setSize("200px", "100%");
	    
	    lblWLastName = new Label(CloudMobile.constants.wInvalidate());
	    lblWLastName.setStyleName("gwt-LblWarning");
	    flexTable.setWidget(2, 2, lblWLastName);
	    lblWLastName.setWidth("100%");
	    flexTable.getCellFormatter().setHeight(2, 2, "20px");
	    flexTable.getCellFormatter().setWidth(2, 2, "130px");
	    lblWLastName.setVisible(false);
	    
	    Label lblAddress = new Label(CloudMobile.constants.address()+":");
	    flexTable.setWidget(3, 0, lblAddress);
	    flexTable.getCellFormatter().setHeight(3, 0, "20px");
	    flexTable.getCellFormatter().setWidth(3, 0, "150px");
	    
	    address = new TextBox();
	    flexTable.setWidget(3, 1, address);
	    flexTable.getCellFormatter().setHeight(3, 1, "20px");
	    flexTable.getCellFormatter().setWidth(3, 1, "200px");
	    address.setSize("200px", "100%");
	    
	    lblWAddress = new Label(CloudMobile.constants.wInvalidate());
	    lblWAddress.setStyleName("gwt-LblWarning");
	    flexTable.setWidget(3, 2, lblWAddress);
	    lblWAddress.setWidth("100%");
	    flexTable.getCellFormatter().setHeight(3, 2, "20px");
	    flexTable.getCellFormatter().setWidth(3, 2, "130px");
	    lblWAddress.setVisible(false);
	    
	    Label lblCity = new Label(CloudMobile.constants.city()+":");
	    lblCity.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.setWidget(4, 0, lblCity);	    
	    lblCity.setWidth("180px");
	    flexTable.getCellFormatter().setHeight(4, 0, "20px");
	    flexTable.getCellFormatter().setWidth(4, 0, "180px");
	    
	    city = new TextBox();
	    flexTable.setWidget(4, 1, city);
	    flexTable.getCellFormatter().setHeight(4, 1, "20px");
	    flexTable.getCellFormatter().setWidth(4, 1, "150px");
	    city.setSize("95%", "100%");
	    
	    lblWCity = new Label(CloudMobile.constants.wInvalidate());
	    lblWCity.setStyleName("gwt-LblWarning");
	    flexTable.setWidget(4, 2, lblWCity);
	    lblWCity.setWidth("120px");
	    lblWCity.setVisible(false);
	    
	    Label lblCP = new Label(CloudMobile.constants.cp()+":");
	    lblCP.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.setWidget(5, 0, lblCP);	    
	    lblCP.setWidth("180px");
	    flexTable.getCellFormatter().setHeight(5, 0, "20px");
	    flexTable.getCellFormatter().setWidth(5, 0, "180px");
	    
	    zp = new TextBox();
	    flexTable.setWidget(5, 1, zp);
	    flexTable.getCellFormatter().setHeight(5, 1, "20px");
	    flexTable.getCellFormatter().setWidth(5, 1, "150px");
	    zp.setSize("95%", "100%");
	    
	    lblWZP = new Label(CloudMobile.constants.wInvalidate());
	    lblWZP.setStyleName("gwt-LblWarning");
	    flexTable.setWidget(5, 2, lblWZP);
	    lblWZP.setWidth("120px");
	    lblWZP.setVisible(false);
	    
	    Label lblTelephone = new Label(CloudMobile.constants.telephone()+":");
	    lblTelephone.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.setWidget(6, 0, lblTelephone);
	    flexTable.getCellFormatter().setHeight(6, 0, "20px");
	    flexTable.getCellFormatter().setWidth(6, 0, "150px");
	        
	    telephone = new TextBox();
	    flexTable.setWidget(6, 1, telephone);
	    flexTable.getCellFormatter().setHeight(6, 1, "20px");
	    flexTable.getCellFormatter().setWidth(6, 1, "200px");
	    telephone.setSize("200px", "100%");
	    
	    lblWTelephone = new Label(CloudMobile.constants.wInvalidate());
	    lblWTelephone.setStyleName("gwt-LblWarning");
	    flexTable.setWidget(6, 2, lblWTelephone);
	    flexTable.getCellFormatter().setHeight(6, 2, "20px");
	    lblWTelephone.setWidth("130px");
	    flexTable.getCellFormatter().setWidth(6, 2, "130px");
	    lblWTelephone.setVisible(false);
	    
	    Grid grid = new Grid(1, 2);
	    flexTable.setWidget(7, 1, grid);
	    flexTable.getCellFormatter().setHeight(7, 1, "28px");
	    grid.setSize("210px", "28px");
	    
	    btnCancelar = new Button(CloudMobile.constants.cancel());
	    grid.setWidget(0, 1, btnCancelar);
	    grid.getCellFormatter().setHeight(0, 1, "28px");
	    btnCancelar.setSize("100px", "28px");
	    
	    btnSave = new Button(CloudMobile.constants.save());
	    grid.setWidget(0, 0, btnSave);
	    grid.getCellFormatter().setHeight(0, 0, "28px");
	    btnSave.setSize("100px", "28px");
	    flexTable.getCellFormatter().setVerticalAlignment(1, 2, HasVerticalAlignment.ALIGN_MIDDLE);
	    flexTable.getCellFormatter().setVerticalAlignment(2, 2, HasVerticalAlignment.ALIGN_MIDDLE);
	    flexTable.getCellFormatter().setVerticalAlignment(3, 2, HasVerticalAlignment.ALIGN_MIDDLE);
	    flexTable.getCellFormatter().setVerticalAlignment(4, 2, HasVerticalAlignment.ALIGN_MIDDLE);
	    flexTable.getCellFormatter().setHorizontalAlignment(4, 1, HasHorizontalAlignment.ALIGN_CENTER);
	    flexTable.getCellFormatter().setHorizontalAlignment(3, 1, HasHorizontalAlignment.ALIGN_CENTER);
	    flexTable.getCellFormatter().setHorizontalAlignment(2, 1, HasHorizontalAlignment.ALIGN_CENTER);
	    flexTable.getCellFormatter().setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_CENTER);
	    flexTable.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.getCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT);
	    flexTable.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.getCellFormatter().setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.getCellFormatter().setHorizontalAlignment(3, 0, HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.getCellFormatter().setHorizontalAlignment(4, 0, HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.getCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_MIDDLE);
	    flexTable.getCellFormatter().setVerticalAlignment(2, 0, HasVerticalAlignment.ALIGN_MIDDLE);
	    flexTable.getCellFormatter().setVerticalAlignment(3, 0, HasVerticalAlignment.ALIGN_MIDDLE);
	    flexTable.getCellFormatter().setVerticalAlignment(4, 0, HasVerticalAlignment.ALIGN_MIDDLE);
	    setSize("420px", "264px");
	    setGlassEnabled(true);
	    center();
	    show();
	}

	@Override
	public HasValue<String> getFirstName() {
		return firstName;
	}

	@Override
	public HasValue<String> getLastName() {
		return lastName;
	}

	@Override
	public HasValue<String> getAddress() {
		return address;
	}
	
	@Override
	public HasValue<String> getTelephone() {
		return telephone;
	}

	@Override
	public HasClickHandlers getSaveButton() {
		return btnSave;
	}
	
	@Override
	public void hide() {
	    super.hide();
	}
	
	@Override
	  public Widget asWidget() {
	    return this;
	  }

	@Override
	public HasClickHandlers getCancelButton() {
		return btnCancelar;
	}

	@Override
	public void setTextPopup(String text) {
		setText(text);	
	}

	@Override
	public void enableSave(boolean flag) {
		btnSave.setEnabled(flag);
	}

	@Override
	public String getTextPopup() {
		return getText();
	}

	@Override
	public HasText getId() {
		return id;
	}

	@Override
	public void setVisibeWName(boolean visible) {
		lblWFirstName.setVisible(visible);
		
	}

	@Override
	public void setVisibeWLastName(boolean visible) {
		lblWLastName.setVisible(visible);
		
	}

	@Override
	public void setVisibeWTel(boolean visible) {
		lblWTelephone.setVisible(visible);
	}

	@Override
	public void setVisibeWAddress(boolean visible) {
		lblWAddress.setVisible(visible);	
	}

	@Override
	public HasValue<String> getZP() {
		return zp;
	}

	@Override
	public HasValue<String> getCity() {
		return city;
	}

	@Override
	public void setVisibeWCP(boolean visible) {
		lblWZP.setVisible(visible);
		
	}

	@Override
	public void setVisibeWCity(boolean visible) {
		lblWCity.setVisible(visible);
		
	}	
}
